package com.newtouch.bxzs.policy.service.impl;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.newtouch.bxzs.common.base.em.CompanyParameterTypeEnum;
import com.newtouch.bxzs.common.base.em.SystemParamsEnum;
import com.newtouch.bxzs.common.base.util.RedisUtils;
import com.newtouch.bxzs.common.base.util.SendHttpRequestUtils;
import com.newtouch.bxzs.policy.model.bo.*;
import com.newtouch.bxzs.policy.model.vo.*;
import com.newtouch.bxzs.policy.service.PolicyInsuranceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 银行调保险---保单管理实现类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 13:33</td>
 * <td>linhongxi</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author linhongxi
 * @version 1.0.0
 * @since 1.0.0
 */
@Service
public class PolicyInsuranceServiceImpl implements PolicyInsuranceService {
    @Autowired
    private RedisUtils redisUtils;

    /**
     * 根据保单号查询个人保单详情信息
     * com.newtouch.bxzs.policy.service.PolicyService#getIndividualPolicyInfo
     * @param policyInfoVO 个人保单详情信息查询条件
     * @return 个人保单详情信息
     */
    @Override
    public PolicyBO getIndividualPolicyInfoInsurance(PolicyInfoVO policyInfoVO) {
        SendHttpRequestUtils<PolicyInfoVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.QUERY_POLICY_INFO.getCode());
        return JSON.toJavaObject(sendHttpRequest.sendHttpRequestToJson(policyInfoVO, url),PolicyBO.class);
    }

    /**
     * 根据保单号获取保全列表
     *
     * @param policyInfoPageVO 个人保单详情--保全信息查询条件
     *
     * @return 个人保单详情--保全信息
     */
    @Override
    public List<PreservationBO> getPolicyPreservationInsurance(PolicyInfoPageVO policyInfoPageVO){
        SendHttpRequestUtils<PolicyInfoPageVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.QUERY_POLICY_INFO_PRESERVATION.getCode());
        return  JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(policyInfoPageVO,url).toJSONString(),PreservationBO.class);
    }

    /**
     * 根据保单号获取理赔列表
     *
     * @param policyInfoPageVO 个人保单详情--理赔信息查询条件
     *
     * @return 个人保单详情--理赔信息
     */
    @Override
    public List<ClaimsBO> getPolicyClaimsInsurance(PolicyInfoPageVO policyInfoPageVO){
        //调用外部接口获取个单详情中的理赔信息
        SendHttpRequestUtils<PolicyInfoPageVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.QUERY_POLICY_INFO_CLAIMS.getCode());
        return  JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(policyInfoPageVO, url).toJSONString(),ClaimsBO.class);
    }
    /**
     * 根据查询条件获取新契约进度列表
     *
     * @param policyNewContractVO 个人保单新契约进度列表查询条件
     *
     * @return 个人保单新契约进度列表
     */
    @Override
    public List<PolicyNewContractListBO> getPolicyNewContractListInsurance(PolicyNewContractVO policyNewContractVO){
        SendHttpRequestUtils<PolicyNewContractVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.QUERY_POLICY_NEW_CONTRACT.getCode());
        return JSONArray.parseArray(sendHttpRequest.sendHttpRequestToArray(policyNewContractVO, url).toJSONString(),PolicyNewContractListBO.class);
    }

    /**
     * 根据保单号获取新契约进度详情
     *
     * @param policyNewContractInfoVO 个人保单新契约进度详情查询条件
     *
     * @return 个人保单新契约进度详情
     */
    @Override
    public PolicyNewContractInfoBO getPolicyNewContractInfoInsurance(PolicyNewContractInfoVO policyNewContractInfoVO){
        //调用外部接口获取个单新契约进度详情信息
        SendHttpRequestUtils<PolicyNewContractInfoVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.QUERY_POLICY_NEW_CONTRACT_INFO.getCode());
        return JSON.toJavaObject(sendHttpRequest.sendHttpRequestToJson(policyNewContractInfoVO, url),PolicyNewContractInfoBO.class);
    }

    /**
     * 根据查询条件获取保全进度列表
     *
     * @param preservationVO 个人保单保全进度列表查询条件
     *
     * @return 个人保单保全进度列表
     */
    @Override
    public List<PreservationProgressListBO> getPreservationProgressListInsurance(PreservationVO preservationVO){
        SendHttpRequestUtils<PreservationVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(SystemParamsEnum.QUERY_POLICY_PRESERVATION.getCode());
        return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(preservationVO, url).toJSONString(),PreservationProgressListBO.class);
    }
    /**
     * 根据保单号获取保全进度详情
     *
     * @param preservationProgressInfoVO 个人保单保全进度详情查询条件
     *
     * @return 个人保单保全进度详情查询条件
     */
    @Override
    public PreservationProgressInfoBO getPreservationProgressInfoInsurance(PreservationProgressInfoVO preservationProgressInfoVO){
        //调用外部接口获取个单保全进度详情信息
        SendHttpRequestUtils<PreservationProgressInfoVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(CompanyParameterTypeEnum.QUERY_POLICY_PRESERVATION_INFO.getCode());
        return JSON.toJavaObject(sendHttpRequest.sendHttpRequestToJson(preservationProgressInfoVO, url),PreservationProgressInfoBO.class);
    }

    /**
     * 根据查询条件获取理赔进度列表
     *
     * @param claimsVO 个人保单理赔进度列表查询条件
     *
     * @return 个人保单理赔进度列表
     */
    @Override
    public List<ClaimsProgressListBO> getClaimsProgressListInsurance(ClaimsVO claimsVO){
        SendHttpRequestUtils<ClaimsVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(CompanyParameterTypeEnum.QUERY_POLICY_CLAIMS.getCode());
        return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(claimsVO, url).toJSONString(),ClaimsProgressListBO.class);
    }

    /**
     * 根据查询条件获取满期保单列表
     *
     * @param expirationPolicyVO 个人保单满期列表查询条件
     *
     * @return 个人保单满期列表
     */
    @Override
    public List<ExpirationPolicyBO> getExpirationPolicyListInsurance(ExpirationPolicyVO expirationPolicyVO){
        SendHttpRequestUtils<ExpirationPolicyVO> sendHttpRequest = new SendHttpRequestUtils<>();
        String url = redisUtils.get(CompanyParameterTypeEnum.QUERY_POLICY_EXPIRATION.getCode());
        return  JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(expirationPolicyVO, url).toJSONString(),ExpirationPolicyBO.class);
    }

    /**
     * 根据查询条件获取续期保单列表
     *
     * @param renewalPolicyVO 个人保单续期列表查询条件
     *
     * @return 个人保单续期列表
     */
    @Override
    public List<RenewalPolicyListBO> getRenewalPolicyListInsurance(RenewalPolicyVO renewalPolicyVO){
        //调用外部接口查询续期保单列表
        SendHttpRequestUtils<RenewalPolicyVO> sendHttpRequest = new SendHttpRequestUtils<>();
            String url = redisUtils.get(CompanyParameterTypeEnum.QUERY_POLICY_RENEWAL.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(renewalPolicyVO, url).toJSONString(),RenewalPolicyListBO.class);
    }
}
